package com.mmc.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mmc.entity.Content;
import com.mmc.entity.ContentCategory;
import com.mmc.entity.VO.ContentListVO;
import com.mmc.mapper.ContentMapper;
import com.mmc.result.PageResult;
import com.mmc.service.IContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-13
 */
@Service
public class ContentServiceImpl extends ServiceImpl<ContentMapper, Content> implements IContentService {




    @Override
    public PageResult<Content> selectContentList(ContentListVO content) {
        LambdaQueryWrapper<Content> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(content.getTitle()),Content::getTitle,content.getTitle())
                .eq(content.getCategoryId()!=null,Content::getCategoryId,content.getCategoryId())
                .eq(content.getSortOrder() != null,Content::getSortOrder,content.getSortOrder());
        Page<Content> contentPage = this.baseMapper.selectPage(new Page<>(content.getPageNum(), content.getPageSize()), wrapper);
        return new PageResult<>(contentPage.getTotal(),contentPage.getRecords());
    }

    @Override
    public List<Content> findById(long l) {
        LambdaQueryWrapper<Content> contentLambdaQueryWrapper=new LambdaQueryWrapper<>();
        contentLambdaQueryWrapper.eq(Content::getCategoryId,l);
        List<Content> list = this.list(contentLambdaQueryWrapper);
        return list;
    }
}
